package com.month.ai.controller;
import com.month.ai.tools.FunctionTools;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

import static org.springframework.ai.chat.client.advisor.AbstractChatMemoryAdvisor.CHAT_MEMORY_CONVERSATION_ID_KEY;

@RestController
@RequestMapping("/ai")
@Tag(name = "对话模块")
public class chatController {
    @Autowired
    private  ChatClient chatClient;


    //阻塞输出
    @Operation(summary = "阻塞输出对话请求")
    @GetMapping("/chat")
    public String chat(String msg){
        return chatClient.prompt().
                user(msg).
                call().content();
    }
    //流式输出----(多论对话)
    @Operation(summary = "流式输出对话请求")
    @GetMapping(value = "/chatStream", produces = "text/html;charset=utf-8")
    public Flux<String> chatStream(String msg, String chatId){
        return chatClient.prompt()
                .system("您是算术计算器的代理。\n" +
                        "您能够支持加法运算、乘法运算等操作，其余功能将在后续版本中添加，如果用户问的问题不支持请告知详情。\n" +
                        "\t\t\t\t\t    在提供加法运算、乘法运算等操作之前，您必须从用户处获取如下信息：两个数字，运算类型。\n" +
                        "\t\t\t\t\t    请调用自定义函数执行加法运算、乘法运算。\n" +
                        "\t\t\t\t\t    请讲中文。")
                .user(msg)
                .advisors(a -> a.param(CHAT_MEMORY_CONVERSATION_ID_KEY,chatId))
                .stream()
                .content();
    }



}
